home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Linux / SLAX 6.0.8 / slax-6.0.8.iso / slax / base / 006-devel.lzm / usr / include / arts / artsmidi.idl < prev    next >
Encoding:
Text File  |  2005-09-10  |  9.3 KB  |  380 lines

  1.     /*
  2.  
  3.     Copyright (C) 2000 Stefan Westerfeld
  4.                        stefan@space.twc.de
  5.  
  6.     This library is free software; you can redistribute it and/or
  7.     modify it under the terms of the GNU Library General Public
  8.     License as published by the Free Software Foundation; either
  9.     version 2 of the License, or (at your option) any later version.
  10.   
  11.     This library is distributed in the hope that it will be useful,
  12.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  14.     Library General Public License for more details.
  15.    
  16.     You should have received a copy of the GNU Library General Public License
  17.     along with this library; see the file COPYING.LIB.  If not, write to
  18.     the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  19.     Boston, MA 02111-1307, USA.
  20.  
  21.     */
  22.  
  23. /*
  24.  * DISCLAIMER: The interfaces in artsmidi.idl (and the derived .cc/.h files)
  25.  *             DO NOT GUARANTEE BINARY COMPATIBILITY YET.
  26.  *
  27.  * They are intended for developers. You shouldn't expect that applications in
  28.  * binary form will be fully compatibile with further releases of these
  29.  * interfaces.
  30.  */
  31.  
  32. #include <artsflow.idl>
  33.  
  34. module Arts {
  35.  
  36. /* This is modelled somewhat after
  37.     - the AudioManager concept
  38.     - the aRts-0.3.4.1 MidiPort concept
  39.     - libkmid
  40.  
  41.    It adds timing as new feature compared to older implementation, and also
  42.    tries to do the full set of midi operations.
  43.  
  44.    It's current state is "experimental", and "binary compatibility not kept".
  45.  */
  46.  
  47. /**
  48.  * an absolute timestamp
  49.  */
  50. struct TimeStamp {
  51.     long sec,usec;
  52. };
  53.  
  54. /**
  55.  * different status of a midi command
  56.  */
  57. enum MidiCommandStatus {
  58. // Masks:
  59.     mcsCommandMask        = 0xf0,
  60.     mcsChannelMask        = 0x0f,
  61.  
  62. // Commands:
  63.     mcsNoteOff            = 0x80,
  64.     mcsNoteOn            = 0x90,
  65.     mcsKeyPressure        = 0xa0,
  66.     mcsParameter        = 0xb0,
  67.     mcsProgram            = 0xc0,
  68.     mcsChannelPressure    = 0xd0,
  69.     mcsPitchWheel        = 0xe0
  70. };
  71.  
  72. /**
  73.  * the following are to be used once status is (mcsParameter|channel):
  74.  */
  75. enum MidiCommandParameter {
  76.     mcpSustain            = 0x40,
  77.     mcpAllNotesOff        = 0x7b
  78. };
  79.  
  80. /**
  81.  * a midi command
  82.  */
  83. struct MidiCommand {
  84.     byte status;
  85.     byte data1;
  86.     byte data2;
  87. };
  88.  
  89. /**
  90.  * a midi event
  91.  */
  92.  
  93. struct MidiEvent {
  94.     TimeStamp time;
  95.     MidiCommand command;
  96. };
  97.  
  98. /**
  99.  * a midi port
  100.  */
  101. interface MidiPort {
  102.     /**
  103.      * the current absolute time (since the existence of the midi device)
  104.      */
  105.     readonly attribute TimeStamp time;
  106.  
  107.     /**
  108.      * the current play time 
  109.      *
  110.      * Some midi devices, for instance synthetic audio devices, have a certain
  111.      * amount of internal buffering. This causes a time difference between
  112.      * where events are currently being rendered, which is the timestamp
  113.      * obtained by "time", and the events that the listener is hearing right
  114.      * now, which is this timestamp, the "playTime".
  115.      */
  116.     readonly attribute TimeStamp playTime;
  117.  
  118.     /**
  119.      * processes a midi command
  120.      */
  121.     oneway void processCommand(MidiCommand command);
  122.  
  123.     /**
  124.      * processes a midi event
  125.      */
  126.     oneway void processEvent(MidiEvent event);
  127. };
  128.  
  129. enum MidiClientDirection { mcdPlay, mcdRecord }; 
  130. enum MidiClientType { mctDestination, mctApplication }; 
  131.  
  132. /**
  133.  * information about a midi client
  134.  */
  135. struct MidiClientInfo {
  136.     long ID;
  137.     sequence<long> connections;
  138.  
  139.     MidiClientDirection direction;
  140.     MidiClientType type;
  141.     string title, autoRestoreID;
  142. };
  143.  
  144. /**
  145.  * a midi manager client
  146.  */
  147. interface MidiClient {
  148.     readonly attribute MidiClientInfo info;
  149.  
  150.     /**
  151.      * you can change the title of your client on the fly - everything else
  152.      * (besides the actual assignment) is static
  153.      */
  154.     attribute string title;
  155.  
  156.     /**
  157.      * creates a new port through which the client can receive data from
  158.      * the midi manager
  159.      */
  160.     void addInputPort(MidiPort port);
  161.  
  162.     /**
  163.      * creates a new port through which the client can send data to the
  164.      * midi manager
  165.      */
  166.     MidiPort addOutputPort();
  167.  
  168.     /**
  169.      * removes a port
  170.      */
  171.     void removePort(MidiPort port);
  172. };
  173.  
  174. interface AudioSync;
  175.  
  176. /**
  177.  * this synchronizes multiple midi clients - it also allows synchronization
  178.  * with audio events
  179.  */
  180. interface MidiSyncGroup {
  181.     /**
  182.      * adds a midi client to the synchronization group
  183.      *
  184.      * hint: during adding the client, the timestamps related to that
  185.      * client will jump
  186.      */
  187.     void addClient(MidiClient client);
  188.  
  189.     /**
  190.      * deletes a midi client from the synchronization group
  191.      */
  192.     void removeClient(MidiClient client);
  193.  
  194.     /**
  195.      * adds an AudioSync object to the synchronization group
  196.      *
  197.      * hint: during adding the AudioSync object, the timestamps related to
  198.      * that object might jump
  199.      */
  200.     void addAudioSync(AudioSync audioSync);
  201.  
  202.     /**
  203.      * deletes an AudioSync object from the synchronization group
  204.      */
  205.     void removeAudioSync(AudioSync audioSync);
  206. };
  207.  
  208. /**
  209.  * Some general notes to the understanding of the midi manager. The midi
  210.  * manager has the task to intelligently assign applications to destinations.
  211.  *
  212.  * It is important to understand what it actually does to understand the
  213.  * distinction first, which is expressed through the "MidiClientType" of
  214.  * each client.
  215.  *
  216.  * APPLICATIONS: An application is a user visible application, that produces
  217.  *    or records midi data. It is important for the understanding of an
  218.  *    application, that an application actually *wants* to be supplied with
  219.  *    data, or wants to get its data played. Thus, adding an application to
  220.  *    the midi manager is an implicit request: "go and find a place where to
  221.  *    put the events to (or get the events from)".
  222.  *
  223.  *    Examples for applications would be games or midi players.
  224.  *
  225.  * DESTINATIONS: A destination is a system service that plays or supplies
  226.  *    midi data. The characteristic here is that a destination is something
  227.  *    that is there if you need it.
  228.  *
  229.  *    Examples for destinations might be might be a hardware device or an
  230.  *    emulation of a hardware device (such as a virtual sampler).
  231.  *
  232.  * So the process is as follows:
  233.  *  - destinations register themselves at the midi manager, and provide
  234.  *    system services in that way
  235.  *
  236.  *  - when the user starts an application (such as a midi player), the midi
  237.  *    manager's task is to assign it to a suitable destination
  238.  *
  239.  *  - the user can interact with the process by changing the way applications
  240.  *    are assigned to destinations - the midi manager will try to learn
  241.  *    what the user wants, and next time do a better job while assigning
  242.  *
  243.  * To actually record or play some data, you need to register a client first,
  244.  * and after that, you can add Input or Output "MidiPort"s to your client,
  245.  * so that you can actually send or receive events with them.
  246.  */
  247. interface MidiManager { // SINGLETON: Arts_MidiManager
  248.     /**
  249.      * a list of clients
  250.      */
  251.     readonly attribute sequence<MidiClientInfo> clients;
  252.  
  253.     /**
  254.      * add a client
  255.      *
  256.      * this creates a new MidiManagerClient
  257.      */ 
  258.     MidiClient addClient(MidiClientDirection direction, MidiClientType type,
  259.                             string title, string autoRestoreID);
  260.  
  261.     /**
  262.      * connect two clients
  263.      */
  264.     void connect(long clientID, long destinationID);
  265.  
  266.     /**
  267.      * disconnect two clients
  268.      */
  269.     void disconnect(long clientID, long destinationID);
  270.  
  271.     /**
  272.      * add a synchronization group
  273.      *
  274.      * this creates a new MidiSyncGroup
  275.      */
  276.     MidiSyncGroup addSyncGroup();
  277. };                                                                              
  278.  
  279. interface MidiTest : MidiPort {
  280. };
  281.  
  282. interface RawMidiPort : MidiPort {
  283.     attribute string device;
  284.     attribute boolean input, output;
  285.     attribute boolean running;
  286.     boolean open();
  287. };
  288.  
  289. interface AlsaMidiGateway {
  290.     boolean rescan();
  291. };
  292.  
  293. interface AlsaMidiPort : MidiPort {
  294.     attribute long client;
  295.     attribute long port;
  296.     boolean open();
  297. };
  298.  
  299. /**
  300.  * EXPERIMENTAL interface for audio synchronization - this allows multiple
  301.  * objects to be started and stopped at a precisely defined timestamp
  302.  */
  303. interface AudioSync {
  304.     /**
  305.      * the current time
  306.      */
  307.     readonly attribute TimeStamp time;
  308.  
  309.     /**
  310.      * the current play time 
  311.      *
  312.      * Since aRts has internal buffering, there is a time difference between
  313.      * where events are currently being rendered, which is the timestamp
  314.      * obtained by "time", and the events that the listener is hearing right
  315.      * now, which is this timestamp, the "playTime".
  316.      */
  317.     readonly attribute TimeStamp playTime;
  318.  
  319.     /**
  320.      * queues calling synthModule.start() later
  321.      *
  322.      * (will keep a reference on the module until executed)
  323.      */
  324.     void queueStart(SynthModule synthModule);
  325.  
  326.     /**
  327.      * queues calling synthModule.stop() later
  328.      *
  329.      * (will keep a reference on the module until executed)
  330.      */
  331.     void queueStop(SynthModule synthModule);
  332.  
  333.     /**
  334.      * atomically executes all queued modification to the flow system
  335.      */
  336.     void execute();
  337.  
  338.     /**
  339.      * atomically executes all queued modifications to the flow system
  340.      * at a given time
  341.      */
  342.     void executeAt(TimeStamp timeStamp);
  343. };
  344.  
  345. /**
  346.  * Midi Timer - can be used to provide timing for midi ports that have
  347.  * no "native" timing.
  348.  */
  349. interface MidiTimer
  350. {
  351.     /**
  352.      * the current time
  353.      */
  354.     readonly attribute TimeStamp time;
  355.  
  356.     /**
  357.      * this will put the event into an event queue and send it to the port
  358.      * once the time for the event has been reached
  359.      */
  360.     oneway void queueEvent(MidiPort port, MidiEvent event);
  361. };
  362.  
  363. /**
  364.  * Uses the system time (i.e. gettimeofday() and similar) to provide midi
  365.  * timing
  366.  */
  367. interface SystemMidiTimer : MidiTimer
  368. {
  369. };
  370.  
  371. /**
  372.  * Uses the audio time (i.e. samples rendered to /dev/dsp) to provide midi
  373.  * timing
  374.  */
  375. interface AudioMidiTimer : MidiTimer
  376. {
  377. };
  378.  
  379. };
  380.